﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Luminal;

namespace Luminoise
{
    public abstract class Module
    {
        static Dictionary<float, Module> constantCache = new Dictionary<float, Module>();

        public abstract string FunctionName { get; }
        public abstract string GetCode();

        public static Module operator +(Module ls, Module rs)
        {
            return new Add(ls, rs);
        }

        public static Module operator -(Module ls, Module rs)
        {
            return new Subtract(ls, rs);
        }

        public static Module operator *(Module ls, Module rs)
        {
            return new Multiply(ls, rs);
        }

        public static Module operator /(Module ls, Module rs)
        {
            return new Divide(ls, rs);
        }

        public static implicit operator Module(float value)
        {
            if (!constantCache.ContainsKey(value))
                constantCache.Add(value, new Constant(value));
            return constantCache[value];
        }
    }
}
